package com.qzsoft.system.modules.sys.message.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.jeemis.platform.security.user.UserDetail;
import com.qzsoft.system.modules.permission.index.dto.FlowDTO;
import com.qzsoft.system.modules.permission.index.service.IndexService;
import com.qzsoft.system.modules.sys.message.dto.SysFlowDataDTO;
import com.qzsoft.system.modules.sys.notice.dao.SysNoticeUserMapper;
import com.qzsoft.system.modules.sys.notice.dto.SysNoticeDto;
import com.qzsoft.system.modules.sys.message.service.SysMessageService;
import com.qzsoft.system.modules.sys.notice.entity.SysNoticeUserEntity;
import com.qzsoft.system.modules.sys.notice.service.SysNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sdmq
 * @date 2019/9/17 20:52
 */
@RestController
@RequestMapping("/sys/mngmessage")
@Api(tags="消息")
public class SysMessageMngController {

    @Autowired
    private SysNoticeService sysNoticeService;

    @Autowired
    private SysMessageService sysMessageService;

    @Autowired
    private IndexService indexService;

    @PostMapping("getnothandlemsgcnt")
    @ApiOperation("检索待办以及未读通知件数")
    public Result<SysNoticeDto> getnothandlemsgcnt(){
        SysNoticeDto dto = new SysNoticeDto();
        // 未读通知条数s
        int noticeNotReadCnt = sysNoticeService.selectNotReadNoticeCount(dto);
        Map<String, Object> param = new HashMap<>();
        int notHandleCnt = indexService.selectFlowListCnt( param);
        dto.setUnHandleMsgCnt(noticeNotReadCnt + notHandleCnt);
        // 待办条数
        return new Result<SysNoticeDto>().ok(dto);
    }

    @PostMapping("updatereadtatus")
    @ApiOperation("更新通知为已读状态")
    public Result updatereadtatus(@RequestBody SysNoticeDto dto){
        sysMessageService.updateReadStatus(dto);
        return new Result();
    }

    @GetMapping("flowdatalist")
    @ApiOperation("列表")
    public Result<IPage<SysFlowDataDTO>> flowdatalist(Page page) {
        IPage<SysFlowDataDTO> list = sysMessageService.getNotAndHandleFlowData(page);
        return new Result<IPage<SysFlowDataDTO>>().ok(list);
    }

    @GetMapping("flowunhandledatalist")
    @ApiOperation("列表")
    public Result<IPage<SysFlowDataDTO>> flowUnhandleDatalist(Page page) {
        IPage<SysFlowDataDTO> list = sysMessageService.getNotHandleFlowData(page);
        return new Result<IPage<SysFlowDataDTO>>().ok(list);
    }



}
